﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ninject;
using Ninject.Parameters;
using Ninject.Syntax;
using System.Web.Mvc;
using LogisticDatabase;
using LogisticDatabase.Models;

namespace LogisticSimulator.Util
{
   public class NinjectDependencyResolver : IDependencyResolver {
   private IKernel kernel;

   public NinjectDependencyResolver() {
     kernel = new StandardKernel();
     AddBindings();
   }

    public object GetService(Type serviceType) {
      return kernel.TryGet(serviceType);
    } 

    public IEnumerable<object> GetServices(Type serviceType) {
     return kernel.GetAll(serviceType);
    }

    private void AddBindings() {
       kernel.Bind<IDataAccess<City>>().To<CityDataAccess>();
       kernel.Bind<IDataAccess<Order>>().To<OrderDataAccess>();
       kernel.Bind<IDataAccess<Product>>().To<ProductDataAccess>();
       kernel.Bind<IDataAccess<Factory>>().To<FactoryDataAccess>();
       kernel.Bind<IWarhouseDataAccess>().To<WarehouseDataAccess>();
   }
  }
} 